<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>完整demo</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    
    
    <script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
    
   <script type="text/javascript" charset="utf-8" src="_src/editor.js"> </script>
    <!--浏览器判断模块-->
    <script type="text/javascript" charset="utf-8" src="_src/core/browser.js"> </script> 
    <!--工具函数包-->
    <script type="text/javascript" charset="utf-8" src="_src/core/utils.js"> </script>
    <!--UE采用的事件基类-->
    <script type="text/javascript" charset="utf-8" src="_src/core/EventBase.js"> </script> 
    <!--dtd html语义化的体现类-->
    <script type="text/javascript" charset="utf-8" src="_src/core/dtd.js"> </script>
    <!--Dom操作工具包-->
    <script type="text/javascript" charset="utf-8" src="_src/core/domUtils.js"> </script>
    <!--Range封装-->
    <script type="text/javascript" charset="utf-8" src="_src/core/Range.js"> </script>
    <!--选区集合 *-->
    <script type="text/javascript" charset="utf-8" src="_src/core/Selection.js"> </script>
    <!--编辑器主类，包含编辑器提供的大部分公用接口-->
    <script type="text/javascript" charset="utf-8" src="_src/core/Editor.js"> </script> 
    <!--维护编辑器一下默认的不在插件中的配置项-->
	<script type="text/javascript" charset="utf-8" src="_src/core/Editor.defaultoptions.js"> </script> 
	<script type="text/javascript" charset="utf-8" src="_src/core/loadconfig.js"> </script>
	<script type="text/javascript" charset="utf-8" src="_src/core/filterword.js"> </script>
	<script type="text/javascript" charset="utf-8" src="_src/core/node.js"> </script>
	<script type="text/javascript" charset="utf-8" src="_src/core/htmlparser.js"> </script>
    <!--<script type="text/javascript" charset="utf-8" src="_src/core/filternode.js"> </script>-->
    <script type="text/javascript" charset="utf-8" src="_src/core/plugin.js"> </script>
    <!--事件-->
    <script type="text/javascript" charset="utf-8" src="_src/core/keymap.js"> </script>
    <!--存储媒介封装-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/core/localstorage.js"> </script>-->




  	<!--插入html字符串插件-->
  	<script type="text/javascript" charset="utf-8" src="_src/plugins/inserthtml.js"> </script>
    <!--源码编辑插件   -->
    <script type="text/javascript" charset="utf-8" src="_src/plugins/source.js"> </script>
    <!--处理特殊键的兼容性问题-->
    <script type="text/javascript" charset="utf-8" src="_src/plugins/keystrokes.js"> </script>
    <!--UE表格操作类-->
    <script type="text/javascript" charset="utf-8" src="_src/plugins/table.core.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/table.cmds.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/table.action.js"> </script>
    
    <!--右键菜单-->
    <script type="text/javascript" charset="utf-8" src="_src/plugins/contextmenu.js"> </script>
    <!--编辑器默认的过滤转换机制-->
  	
  	<!--点击HTML  表格会变小  谷歌不会 ，浏览器兼容问题-->
  	<script type="text/javascript" charset="utf-8" src="_src/plugins/defaultfilter.js"> </script>
  	<!--插入html字符串插件-->
  	<script type="text/javascript" charset="utf-8" src="_src/plugins/inserthtml.js"> </script>
  	<!--自动排版-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/autotypeset.js"> </script>-->
    <!--快捷键提交-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/autosubmit.js"> </script>-->
    <!--背景插件，为UEditor提供设置背景功能-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/background.js"> </script>-->
    
    <!--段落格式-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/justify.js"> </script>
    
    <script type="text/javascript" charset="utf-8" src="_src/plugins/iframe.js"> </script>-->
    <!--涂鸦-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/preview.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/selectall.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/rowspacing.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/lineheight.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/insertcode.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/cleardoc.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/wordcount.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/dragdrop.js"> </script>-->
    <!--撤销上一次执行的命令-->
    <script type="text/javascript" charset="utf-8" src="_src/plugins/undo.js"> </script>
    
    
    <script type="text/javascript" charset="utf-8" src="_src/plugins/copy.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/plugins/paste.js"> </script>
    <!--纯文本粘贴插件-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/puretxtpaste.js"> </script>-->
    <!--有序列表,无序列表插件-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/list.js"> </script>-->
    <!--源码编辑插件-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/source.js"> </script>-->
    <!--设置回车标签p或br-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/enterkey.js"> </script>-->
    <!--处理特殊键的兼容性问题-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/keystrokes.js"> </script>-->
    <!--修复chrome下图片不能点击的问题，出现八个角可改变大小-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/fiximgclick.js"> </script>-->
    <!--为非ie浏览器自动添加a标签-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/autolink.js"> </script>-->
    <!--当输入内容超过编辑器高度时，编辑器自动增高-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/autoheight.js"> </script>-->
    <!--悬浮工具栏-->
    <!--<script type="text/javascript" charset="utf-8" src="_src/plugins/autofloat.js"> </script>-->
    
   
    
    
    
    
    <script type="text/javascript" charset="utf-8" src="_src/ui/ui.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/uiutils.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/uibase.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/popup.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/tablepicker.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/stateful.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/button.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/splitbutton.js"> </script>
    <!--菜单中使用了-->
    <script type="text/javascript" charset="utf-8" src="_src/ui/cellalignpicker.js"> </script>
    <!--导航条-->
    <script type="text/javascript" charset="utf-8" src="_src/ui/toolbar.js"> </script>
    <!--右键菜单的-->
    <script type="text/javascript" charset="utf-8" src="_src/ui/menu.js"> </script>
    <script type="text/javascript" charset="utf-8" src="_src/ui/tablebutton.js"> </script>
    <!--删除后没有编辑-->
    <script type="text/javascript" charset="utf-8" src="_src/adapter/editor.js"> </script>
    <!--图标-->
    <script type="text/javascript" charset="utf-8" src="_src/adapter/editorui.js"> </script>
    
    
    
    <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
    <style type="text/css">
        div{
            width:100%;
        }
    </style>
</head>
<body>
<div>
    <h1>完整demo</h1>
    <script id="editor" type="text/plain" style="width:1024px;height:200px;"></script>
</div>
<div id="btns">
    <div>
        <button onclick="getAllHtml()">获得整个html的内容</button>
        <button onclick="getContent()">获得内容</button>
        <button onclick="setContent()">写入内容</button>
        <button onclick="setContent(true)">追加内容</button>
        <button onclick="getContentTxt()">获得纯文本</button>
        <button onclick="getPlainTxt()">获得带格式的纯文本</button>
        <button onclick="hasContent()">判断是否有内容</button>
        <button onclick="setFocus()">使编辑器获得焦点</button>
        <button onmousedown="isFocus(event)">编辑器是否获得焦点</button>
        <button onmousedown="setblur(event)" >编辑器失去焦点</button>

    </div>
    <div>
        <button onclick="getText()">获得当前选中的文本</button>
        <button onclick="insertHtml()">插入给定的内容</button>
        <button id="enable" onclick="setEnabled()">可以编辑</button>
        <button onclick="setDisabled()">不可编辑</button>
        <button onclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button>
        <button onclick=" UE.getEditor('editor').setShow()">显示编辑器</button>
        <button onclick=" UE.getEditor('editor').setHeight(300)">设置高度为300默认关闭了自动长高</button>
    </div>

    <div>
        <button onclick="getLocalData()" >获取草稿箱内容</button>
        <button onclick="clearLocalData()" >清空草稿箱</button>
    </div>

	</div>
	<div>
	    <button onclick="createEditor()">创建编辑器</button>
	    <button onclick="deleteEditor()">删除编辑器</button>
	</div>

<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor',{
			toolbars : [ [ 'source', //源码
			'inserttable', //插入表格
			'insertrow', //前插入行
			'insertcol', //前插入列
			'mergeright', //右合并单元格
			'mergedown', //下合并单元格
			'deleterow', //删除行
			'deletecol', //删除列
			'splittorows', //拆分成行
			'splittocols', //拆分成列
			'splittocells', //完全拆分单元格
			'deletecaption', //删除表格标题
			'inserttitle', //插入标题
			'mergecells', //合并多个单元格
			'deletetable', //删除表格
			'cleardoc', //清空文档
			'insertparagraphbeforetable', //"表格前插入行"
			] ]
		});


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor('editor').focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor('editor').execCommand( "clearlocaldata" );
        alert("已清空草稿箱")
    }
</script>
</body>
</html>